<template>
  <div>
    <el-form :model="sectionForm" ref="sectionForm" label-width="80px">
      <el-form-item label="适用项目">
        <el-checkbox-group v-model="sectionForm.projectType">
          <el-checkbox
            :label="pro.dictKey"
            name="type"
            v-for="pro in projectTypes"
            :key="pro.dictKey"
            :disabled="!pro.changeable"
          >{{pro.dictValue}}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'check-box-group-demo',
  data() {
    return {
      sectionForm: {
        // 部门表单
        sectionName: "",
        prevSection: "",
        deptType: "",
        projectType: [], // 适用项目
      },
      projectTypes: [],
    };
  },
  mounted() {
      this.getProjectTypes();
  },
  methods: {
    getProjectTypes() {
      // 获取适用项目(配置项)
      // organApi.getDictionaryListByCateory({
      //     cateory: 'project_type'
      // }).then((res) => {
      //     if (res.code === '0') {
      //         let arr = res.data.map(item => {
      //             return {
      //                 id: item.id,
      //                 dictKey: item.dictKey,
      //                 dictValue: item.dictValue,
      //                 checked: item.dictKey === '1', // 物业项目默认是选中的，并且不可以去掉勾选状态
      //                 changeable: item.dictKey !== '1'
      //             }
      //         });
      //         this.projectTypes = arr;
      //     }
      // });
      let res = {
        code: "0",
        isSuccess: true,
        message: "成功",
        errorCode: null,
        data: [
          {
            id: "734",
            dictKey: "1",
            dictValue: "物业项目",
            parentId: "-1",
            cateory: "project_type",
            deleteFlag: 0,
            createTime: 1524814044000,
            updateTime: 1524814044000,
          },
          {
            id: "735",
            dictKey: "2",
            dictValue: "前介项目",
            parentId: "-1",
            cateory: "project_type",
            deleteFlag: 0,
            createTime: 1524814044000,
            updateTime: 1524814044000,
          },
          {
            id: "736",
            dictKey: "3",
            dictValue: "案场项目",
            parentId: "-1",
            cateory: "project_type",
            deleteFlag: 0,
            createTime: 1524814044000,
            updateTime: 1524814044000,
          },
          {
            id: "737",
            dictKey: "4",
            dictValue: "地产项目",
            parentId: "-1",
            cateory: "project_type",
            deleteFlag: 0,
            createTime: 1524814044000,
            updateTime: 1524814044000,
          },
        ],
      };
      if (res.code === "0") {
        let arr = res.data.map((item) => {
          return {
            id: item.id,
            dictKey: item.dictKey,
            dictValue: item.dictValue,
            checked: item.dictKey === "1", // 物业项目默认是选中的，并且不可以去掉勾选状态
            changeable: item.dictKey !== "1",
          };
        });
        this.projectTypes = arr;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>